package PseudoRandomNumberAlgorithm;

import java.math.BigInteger;

public class BBSTest {

    private static final BlumBlumShub bbs = new BlumBlumShub();

    static class BBSTestData {
        private final BigInteger p;
        private final BigInteger q;
        private final BigInteger s;
        private final int num;
        private final String rbs;

        public BBSTestData(String p, String q, String s, int num, String rbs) {
            this.p = new BigInteger(p);
            this.q = new BigInteger(q);
            this.s = new BigInteger(s);
            this.num = num;
            this.rbs = rbs;
        }

        public String getComputeRbs() {
            return bbs.getBBS(p, q, s, num);
        }

        public String getRbs() {
            return rbs;
        }
    }

    public static void main(String[] args) {
        BBSTest();
    }

    private static void BBSTest() {
        BBSTestData[] bbsTestData = new BBSTestData[3];
        bbsTestData[0] = new BBSTestData("383", "503", "101355", 20,
                "11001110000100111010");
        bbsTestData[1] = new BBSTestData("300007", "400031", "43363", 50,
                "01110111111010101110011110011000100100010011111111");
        bbsTestData[2] = new BBSTestData("30000000091", "40000000003", "4295260440", 100,
                "1011010010111101111110111101001000101111110010100111010001110111010000010101101110000000100011100101");
        boolean flag = true;
        for (BBSTestData data : bbsTestData) {
            String computeRbs = data.getComputeRbs();
            System.out.println(computeRbs);
            System.out.println(data.getRbs());
            if (!computeRbs.equals(data.getRbs())) {
                flag = false;
            }
        }
        if (flag) {
            System.out.println("BBSTest：测试通过");
        } else {
            System.out.println("BBSTest：测试不通过");
        }
    }

}
